<template>
  <div class="app-container">
    <!-- 查询表单-->
    <!--element-ui的 date-picker组件默认绑定的时间值是默认世界标准时间，和中国时间差8小时
          设置 value-format="yyyy-MM-dd HH:mm:ss" 改变绑定的值-->
    <div id="content">
      <i class="el-icon-menu">筛选</i>
      <p />
      <el-form :inline="true" :model="slideShowQuery" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="slideShowQuery"
            placeholder="请输入轮播图标题"
          ></el-input>
        </el-form-item>
      
        <el-button type="primary" icon="el-icon-search" @click="getList()"
          >筛选</el-button
        >
        <el-button type="default" @click="resetData()">清空筛选条件</el-button>
      </el-form>
      <el-row>
        <el-col
          ><div class="grid-content bg-purple">
            <i class="el-icon-menu">轮播图回收站</i>
          </div></el-col
        >
        <el-col><div class="grid-content bg-purple-light"></div></el-col>
        <el-col
          ><div class="grid-content bg-purple add">
            <router-link :to="{ path: '/list/slideShow' }">
              <el-button type="primary" icon="el-icon-notebook-2"
                >返回轮播图列表</el-button
              >
            </router-link>
          </div></el-col
        >
      </el-row>
      <p />
      <!--表格-->
       <el-table
        v-loading="listLoading"
        :data="list"
        @selection-change="handleSelectionChange"
        element-loading-text="数据加载中"
        border
        fit
        stripe
        highlight-current-row
        style="width: 100%"
      >
        <!--数据展示- class="head_pic"-->
        <el-table-column
          type="selection"
          width="65"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="id"
          label="轮播图id"
          width="130"
          align="center"
        />
        <el-table-column
          prop="name"
          label="轮播图名称"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column label="缩略图" width="260" align="center">
          <template slot-scope="scope">
            　　　　<img :src="scope.row.pic" width="40" height="40" />
            　　</template
          >
          ></el-table-column
        >
        <el-table-column
          prop="createTime"
          label="上传时间"
          width="260"
          align="center"
        />
        <el-table-column label="操作" width="300" align="center">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click="removeDataById(scope.row.id)"
              >彻底删除</el-button
            > 
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-delete"
              @click="rollbackDataById(scope.row.id)"
              >恢复</el-button
            >
          </template>
          
           
          
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        background
        style="padding: 30px 0; text-align: center"
        layout="total, prev, pager, next, jumper"
        @current-change="getList"
      />
    </div>
  </div>
</template>

<script>
//引入调用slideShow.js文件
import slideShow from "@/api/slideShow";

export default {
  //写核心代码位置
  // data:{
  // },
  data() {
    //定义变量和初始值
    return {
      listLoading: true, // 是否显示loading信息
      list: null, //查询之后接口返回集合
      page: 1, //当前页
      limit: 5, //每页记录数
      total: 0, //总记录数
      slideShowQuery: '',
       
      checkList: [],
    };
  },
  created() {
    //页面渲染之前执行，一般调用methods定义的方法
    //调用
    this.getList();
  },
  mounted() {
    this.listLoading = false;
  },
  methods: {
    //创建具体的方法，调用slideShow.js定义的方法
    //获取轮播图列表的方法,默认是第一页
    getList(page = 1) {
      this.page = page;
      slideShow
        .getSlideShowListPage(this.page, this.limit, this.slideShowQuery,2)
        .then((response) => {
          //请求成功
          //response接口返回的数据
        
          this.list = response.data.list;
          this.total = response.data.total;
        });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      //获取所有选中项的gh(工号)属性的值
      this.checkList = selection.map((item) => item.id);
    },
    resetData() {
      //清空的方法
      //表单输入项数据清空
      this.slideShowQuery='';
      //查询所有轮播图数据
      this.getList();
      this.$message({
        type: "success",
        message: "清空成功!",
      });
    },
    //从回收站恢复
    recoverDataById(id) {
      this.checkList.push(id);
      this.$confirm(
        "此操作将会从回收站恢复选中的数据,请问是否继续?",
        "提示",

        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用恢复的方法
          slideShow.recoverSlideShow(this.checkList).then((response) => {
            //删除成功
            //提示信息
            this.checkList = [];
            this.$message({
              type: "success",
              message: "数据恢复成功!",
            });
            //回到列表页面
            this.getList();
          });
        })
        .catch((e) => {
          this.checkList = [];

          this.$message({
            type: "info",
            message: "已取消恢复!",
          });
        }); //点击取消，执行catch方法
    },
    //删除轮播图的方法
    removeDataById(id) {
      this.checkList.push(id);
      this.$confirm(
        "此操作将会彻底删除数据,请问是否继续?",
        "提示",

        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          slideShow.removeShowListPage(this.checkList,3).then((response) => {
            //删除成功
            //提示信息
            this.checkList = [];
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            //回到列表页面
            this.getList();
          });
        })
        .catch((e) => {
          this.checkList = [];

          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    }, 
    rollbackDataById(id) {
      this.checkList.push(id);
      this.$confirm(
        "此操作将会恢复数据,请问是否继续?",
        "提示",

        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          slideShow.removeShowListPage(this.checkList,1).then((response) => {
            //删除成功
            //提示信息
            this.checkList = [];
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            //回到列表页面
            this.getList();
          });
        })
        .catch((e) => {
          this.checkList = [];

          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    }
  },
};
</script>
<style>
#content {
  width: 80%;
  margin: 0 auto;
}
.el-row .el-col-24 {
  width: 150px;
}
.el-col-24:nth-child(3),
.el-col-24:nth-child(4) {
  float: right;
}
</style>